<!DOCTYPE html>
<html>
<head>
	<meta content="text/html;charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
	<meta http-equiv ="Pragma" content = "no-cache"/>
	<meta http-equiv="Cache-Control" content="no cache" />
	<meta http-equiv="Expires" content="0" />
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
	<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
	<meta name="apple-mobile-web-app-capable" content="yes"/>
	<meta name="format-detection" content="telephone=no"/>
	<script src="https://cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
	<link href="https://cdn.bootcss.com/pace/1.0.2/themes/pink/pace-theme-flash.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="../../plugins/layui/css/layui.css" media="all"/>
	<link rel="stylesheet" type="text/css" href="../../css/fs.css" media="all"/>
	<script type="text/javascript" src="../../plugins/jquery/jquery.min.js"></script>
	<script type="text/javascript" src="../../plugins/home/common.js"></script>
	<script src="https://cdn.bootcss.com/layer/2.3/layer.js"></script>
	<script type="text/javascript" src="../../plugins/layui/layui.js"></script>
	<script type="text/javascript" src="../../plugins/frame/js/fsDict.js?v=1.5.0"></script>
	<script type="text/javascript" src="../../plugins/frame/js/fs.js?v=1.5.0"></script>
	<script type="text/javascript" src="../../plugins/frame/js/frame.js?v=1.5.0"></script>
	<script src="https://cdn.bootcss.com/axios/0.19.0/axios.min.js"></script>
	<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
	<script type="text/javascript" src="../../scripts/home/yunhetong.js"></script>
	<script type="text/javascript" src="../../scripts/home/magerIndcInfo.js"></script>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
	<legend>选择管理人</legend>
</fieldset>

<table id="fsDatagrid" lay-filter="fsDatagrid" class="fsDatagrid" isLoad="1" url="/tpdtmandator/findAllList.shtml" isPage="0" sortType="1" defaultForm="query_form" height="450"></table>

<div class="fsDatagridCols">
	<!--<p type="numbers" title="序号"/>-->
	<p field="cType" templet="#column2Tpl"  width="70"/>
	<p field="cName" title="管理人名称" />
</div>
<script type="text/html" id="column2Tpl">
	{{# if(d.cType=='Y'){}}
	{{#} else if(d.cType=='N'){}}
	<input type="radio" id="{{d.lMandatorid}}" data-name="{{d.cName}}" value="{{d.lMandatorid}}" lay-filter="rdo" name="rdo" />
	{{#} else {}}

	{{#}}}
</script>
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
	</div>
</script>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
	<legend>填写认证信息</legend>
</fieldset>
<form class="layui-form" action="">
	<div  id="app">
		<div class="layui-form">
			<table class="layui-table">
				<colgroup>
					<col width="20%">
					<col>
				</colgroup>
				<thead>
				<tr>
					<th>管理人名称</th>
					<th id="custNmH"></th>
				</tr>
				</thead>
			</table>
		</div>
		<div class="layui-form-item">
			<input type="hidden" id="custNm" name="custNm" lay-verify="custNm" title="管理人">
			<input type="hidden" id="crmMagerId" name="crmMagerId" title="CRM对应管理人ID">
			<label class="layui-form-label">证件类型</label>
			<div class="layui-input-block">
				<input type="hidden" id="certifyType" name="certifyType"/>
				<select name="cardType" lay-filter="cardTypeFilter"   lay-verify="required">
					<option value=""></option>
					<option :value="item.cKeyValue"  v-for="item in cardTypeList">{{item.cCaption}}</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">证件号码</label>
			<div class="layui-input-block">
				<input type="text" name="cardNo" lay-verify="required|cardNumber" autocomplete="off" class="layui-input" maxlength="18">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">手机号码</label>
			<div class="layui-input-block">
				<input type="tel" name="mobile" lay-verify="required|phone|number" autocomplete="off" class="layui-input" maxlength="11">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<a class="layui-btn" lay-submit="" lay-filter="demo1">认证</a>
			</div>
		</div>
	</div>
</form>

<script>
    /**
     *管理人信息相关操作
     * @author xianyun
     * 管理人新增--从magerIndcInfo.js里面单独提取出来，要不然服务器上面，认证成功之后，父页面不刷新
     * @param custNm 企业名称
     * @param certTyp 证件类型;前台获取,存类型ID
     * @param certNo 认证号码
     * @param mobileNo 手机号
     * @param crmMagerId CRM对应管理人ID
     * @param caCustId 客户ID
     * @param idenUser 认证人ID
     */
    function addMagerIndcInfoSave(custNm,certTyp,certNo,mobileNo,crmMagerId,caCustId,idenUser){
        var url=getProjectApiUrl()+"/api/v1/magerIndcInfo/add";
        var param={"custNm":custNm,"certTyp":certTyp,"certNo":certNo,"mobileNo":mobileNo,"crmMagerId":crmMagerId,"caCustId":caCustId,"idenUser":idenUser};
        var result=sendMyAjaxPost(url,param);
        if(result.code==0){
            layer.alert("认证成功", {
                icon: 6,
                skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
            },function () {
                parent.layer.closeAll();
                parent.parentReload();//刷新父页面
            })
        }else{
            messageInfo(result.msg);
            return false;
        }
    }
    layui.use('form', function(){
        var form = layui.form;
        //监听提交
        form.on('submit(demo1)', function(data){
            var custNm=data.field.custNm;//企业名称
            var certifyType=$("#certifyType").val();//企业相关证件
            var certifyNum=data.field.cardNo;//认证号码
            var phoneNo=data.field.mobile;//企业类型用户的手机号
            var result=queryUserNo(certifyNum);
            var crmMagerId=$("#crmMagerId").val();
            var caCustId="";//客户ID
            if(result.code==200){
                caCustId=result.data[0];
                caCustId=JSON.stringify(caCustId);
                caCustId=caCustId.substring(1,caCustId.length-1);
                caCustId=caCustId.split(":")[1];
			}else{
				//没有返回用户id，则调用企业用户
				var result=createCompanyUser(custNm,certifyType,certifyNum,phoneNo);
                console.log("createCompanyUser..................返回结果"+JSON.stringify(result));
				if(result.code==20209){
                    messageInfo(result.msg);
                    return false;
				}else{
                    caCustId=result.data.signerId;
				}
			}

			//插入表MAGER_INDC_INFO
			var idenUser=getCurrentLoginUser();
            addMagerIndcInfoSave(custNm,certifyType,certifyNum,phoneNo,crmMagerId,caCustId,idenUser);
        });
        //监听select
        form.on('select(cardTypeFilter)', function (data) {
			$("#certifyType").val(data.value);
        });
        //监听radio
        form.on('radio(rdo)', function (data) {
            console.log(JSON.stringify(data));
			var id=data.value;
			var name=$("#"+id).attr('data-name');
            $("#custNmH").html(name);
            $("#custNm").val(name);
            $("#crmMagerId").val(id);
        });
        //自定义校验规则
        form.verify({
            username: function(value, item){ //value：表单的值、item：表单的DOM对象
                if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
                    return '用户名不能有特殊字符';
                }
                if(/(^\_)|(\__)|(\_+$)/.test(value)){
                    return '用户名首尾不能出现下划线\'_\'';
                }
                if(/^\d+\d+\d$/.test(value)){
                    return '用户名不能全为数字';
                }
            }
            //我们既支持上述函数式的方式，也支持下述数组的形式
            //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
            ,pass: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ],
            cardNumber:function(value,item){
                var type=$("#certifyType").val();
                if(type==1||type==2){
                    if(value.length!=18){
                        return "证件号码格式错误";
					}
				}else{
                    if(value.length!=9){
                        return "证件号码格式错误";
					}
				}
			}
              ,
            custNm:[
                /.*[^\s]/
                ,'请先选择管理人'
            ]
        });

    });
    var domain=getRootPath("1");
    var test="";

    new Vue({
        el: '#app',
        data () {
            return {
                cardTypeList: []
            }
        },
        mounted () {
            axios.post(domain+"/v1/cardType/get",{
                    //firstName: 'Fred',        // 参数 firstName
                    //lastName: 'Flintstone'    // 参数 lastName
                })
                .then(response => (this.cardTypeList = response.data.data))
                .catch(function (error) { // 请求失败处理
                    console.log(error);
                });
        }
    })

</script>

</body>
</html>
